package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.PaymentTaskBaseEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author: 汪腾伟
 * @date: 2020/7/27
 * @desrcption: 新回款计划枚举码
 * @version:1.0
 */
@Getter
public enum PaymentTaskEnum {
    //新回款计划模板设置字段
    //other_1：基础消息
    BASE_INFO(PaymentTaskBaseEnum.BASE_INFO.getAttr(), "enum.paymentTask.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //text_2：客户名称(客户id)
    LINK_CUSTOMER(PaymentTaskBaseEnum.LINK_CUSTOMER.getAttr(), "enum.paymentTask.attrName.link_customer", "linkCustomer", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //text_3：合同名称(合同id)
    LINK_CONTRACT(PaymentTaskBaseEnum.LINK_CONTRACT.getAttr(), "enum.paymentTask.attrName.link_contract", "linkContract", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //serialNo：回款计划编号
    PAYMENT_TASK_NO(PaymentTaskBaseEnum.PAYMENT_TASK_NO.getAttr(), "enum.paymentTask.attrName.payment_task_no", "paymentTaskNo", FieldTypeEnum.SERIALNO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //array_1：执行人，值有0、1、2三个，分别表示负责人、协同人、自定义执行人
    EXECUTOR(PaymentTaskBaseEnum.EXECUTOR.getAttr(), "enum.paymentTask.attrName.executor", "executor", FieldTypeEnum.CHECKBOX_GROUP.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 1, ScreenTypeEnum.SCREEN_SHOW.getType()),
    //array_2：自定义执行人 里面的值就是具体的自定义执行者的值
    EXECUTOR_LINKED_TEXT(PaymentTaskBaseEnum.EXECUTOR_LINKED_TEXT.getAttr(), "enum.paymentTask.attrName.executor_linked_text", "executorLinkedText", FieldTypeEnum.USER_GROUP.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //text_8：回款类型
    PAYMENT_TASK_TYPE(PaymentTaskBaseEnum.PAYMENT_TASK_TYPE.getAttr(), "enum.paymentTask.attrName.payment_task_type", "paymentTaskType", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9949, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //num_1：计划收款金额
    PAYMENT_TASK_NUM(PaymentTaskBaseEnum.PAYMENT_TASK_NUM.getAttr(), "enum.paymentTask.attrName.payment_task_num", "paymentTaskNum", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //date_1：预计回款时间
    EXECUTOR_TIME(PaymentTaskBaseEnum.EXECUTOR_TIME.getAttr(), "enum.paymentTask.attrName.executor_time", "executorTime", FieldTypeEnum.DATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //text_4：提醒
    NOTIFY_TYPE(PaymentTaskBaseEnum.NOTIFY_TYPE.getAttr(), "enum.paymentTask.attrName.notify_type", "notifyType", FieldTypeEnum.COMBO.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //date_2：提醒时间
    NOTIFY_TIME(PaymentTaskBaseEnum.NOTIFY_TIME.getAttr(), "enum.paymentTask.attrName.notify_time", "notifyTime", FieldTypeEnum.DATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //text_10：备注
    MEMO(PaymentTaskBaseEnum.MEMO.getAttr(), "enum.paymentTask.attrName.memo", "memo", FieldTypeEnum.TEXTAREA.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9809, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    //other_2：系统消息
    SYSTEM_INFO(PaymentTaskBaseEnum.SYSTEM_INFO.getAttr(), "enum.paymentTask.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //creatorId：创建者id
    CREATOR_ID(PaymentTaskBaseEnum.CREATOR_ID.getAttr(), "enum.paymentTask.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //addTime：添加时间
    ADD_TIME(PaymentTaskBaseEnum.ADD_TIME.getAttr(), "enum.paymentTask.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //updateTime：修改时间
    UPDATE_TIME(PaymentTaskBaseEnum.UPDATE_TIME.getAttr(), "enum.paymentTask.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //text_5：回款状态
    STATUS(PaymentTaskBaseEnum.STATUS.getAttr(), "enum.paymentTask.attrName.status", "status", FieldTypeEnum.COMBO.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9850, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //subForm_1：联系方式
    CONTACT_WAY(PaymentTaskBaseEnum.CONTACT_WAY.getAttr(), "enum.paymentTask.attrName.contact_way", "contactWay", FieldTypeEnum.SUB_FORM.getType(), 1, 1, 1, ShowTypeEnum.DETAIL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //text_6：客户中文名称字段隐藏
    LINK_CUSTOMER_HIDE(PaymentTaskBaseEnum.LINK_CUSTOMER_HIDE.getAttr(), "enum.paymentTask.attrName.link_customer_hide", "linkCustomerHide", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9830, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    //text_7：合同中文名称字段隐藏
    LINK_CONTRACT_HIDE(PaymentTaskBaseEnum.LINK_CONTRACT_HIDE.getAttr(), "enum.paymentTask.attrName.link_contract_hide", "linkContractHide", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9820, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),

    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;

    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    PaymentTaskEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                               Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(PAYMENT_TASK_NO);
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    /**
     * 默认的数据摘要
     *
     * @return
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(LINK_CUSTOMER, LINK_CONTRACT, EXECUTOR, EXECUTOR_TIME);
    }

    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     *
     * @param paymentTaskEnum 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author zcp
     * @date 2019/2/21 14:59
     * @version v1.0
     * @since v1.0
     */
    public static String getEsAttr4Keyword(PaymentTaskEnum paymentTaskEnum) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(paymentTaskEnum.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + paymentTaskEnum.getAttr() + ".keyword";
        }
        return "data." + paymentTaskEnum.getAttr();
    }

    /**
     * 获取拼接es的值
     *
     * @param cache
     * @return
     */
    public static String getAttrConnectData(PaymentTaskEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取新增合同订单时回款计划不可编辑的字段
     *
     * @return
     */
    public static List<PaymentTaskEnum> getLinkFormAddNoEditableList(){
        return Arrays.asList(STATUS,NOTIFY_TYPE);
    }


    /**
     * 获取编辑合同订单时回款计划不可编辑的字段
     *
     * @return
     */
    public static List<PaymentTaskEnum> getLinkFormEditNoEditableList(){
        return Arrays.asList(PAYMENT_TASK_NO,PAYMENT_TASK_NUM,EXECUTOR_TIME,NOTIFY_TYPE,STATUS);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
